﻿/*
   Copyright 2013 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.ServiceModel;
using Flower.Services.Data;

namespace Flower.Services
{
    /// <summary>
    /// State service interface.
    /// </summary>
    [ServiceContract(Namespace = XmlNamespace.StateService)]
    public interface IStateService
    {
        /// <summary>
        /// Saves a process state.
        /// </summary>
        /// <param name="pid">The id of the process.</param>
        /// <param name="state">The serialized state of the process.</param>
        /// <param name="isKeyState">Whether to make the created state a key state.</param>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        Guid Save(string pid, Blob state, bool isKeyState);

        /// <summary>
        /// Gets the latest state of a process.
        /// </summary>
        /// <param name="pid">The id of the process.</param>
        /// <returns>
        /// The latest state or null if no state has been saved for the process.
        /// </returns>
        [OperationContract]
        ProcessState GetLatestState(string pid);
        
        /// <summary>
        /// Marks the latest state of a process as a key state.
        /// </summary>
        /// <param name="pid">The id of the process.</param>
        [OperationContract(IsOneWay = true)]
        void MarkLatestStateAsKeyState(string pid);

        /// <summary>
        /// Marks the latest state of a process as a key state.
        /// </summary>
        /// <param name="pid">The id of the process.</param>
        [OperationContract(IsOneWay = true)]
        void MarkLatestStateAsFinalState(string pid);
    }
}
